<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->


<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="DC.Type" content="topic">
<meta name="DC.Title" content="Restoring PostgreSQL">
<meta name="product" content="">
<meta name="DC.Relation" scheme="URI" content="en-us_topic_0000001792402720.html">
<meta name="prodname" content="">
<meta name="version" content="">
<meta name="brand" content="30-OceanProtect Appliance 1.5.0-1.6.0 Help Center">
<meta name="DC.Publisher" content="20240608">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="EN-US_TOPIC_0000001792402656">
<meta name="DC.Language" content="en-us">
<link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
<title>Restoring PostgreSQL</title>
</head>
<body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px"><a name="EN-US_TOPIC_0000001792402656"></a><a name="EN-US_TOPIC_0000001792402656"></a>

<h1 class="topictitle1">Restoring PostgreSQL</h1>
<div><p>This section describes how to restore a PostgreSQL instance that has been backed up to its original location or a new location.</p>
<div class="section"><h4 class="sectiontitle">Context</h4><p>Backup, archive, and replication copies (data cannot be restored to the original location) can be used for restoration. Data cannot be restored to the original location using archive copies of replication copies.</p>
</div>
<div class="section"><h4 class="sectiontitle">Prerequisites</h4><ul id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001792550248_ul155946913719"><li id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001792550248_li178221624154012">Before restoration, ensure that the remaining space of the data directory at the target location for restoration is greater than the size of the copy used for restoration before reduction. Otherwise, restoration will fail.</li></ul>
<ul id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001792550248_ul1648381342319"><li id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001792550248_li69561792311">Before restoring data to a new location, ensure that the database installation user has the read and write permissions on the target path of restoration.</li><li id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001792550248_li97319774218">If the resource to be restored is an active/standby MPP cluster, ensure that the active/standby database information is correct before stopping the database. Otherwise, you need to scan the restoration target resource.</li></ul>
</div>
<ul><li>If the port of the target instance is occupied, release the occupied port before the restoration.</li><li>If the target instance is a cluster instance, the Pgpool service on each node must have been stopped and the Pgpool port must not be occupied. Otherwise, the restoration fails.</li><li>Stop the PostgreSQL database before the restoration.</li><li>Before restoring a Patroni cluster, clear etcd data.<ol><li>Run the <strong>systemctl stop patroni</strong> command on each node to stop all nodes in the cluster.</li><li>Run the <strong>patronictl -c /etc/patroni/patroni.yml list</strong> command on any cluster node to check whether the node information is cleared. If an empty table is displayed in the command output, the node information has been cleared.<div class="p"><span><img src="en-us_image_0000001927295206.png"></span><ul><li>If yes, no further action is required.</li><li>If no, go to the next step.</li></ul>
</div>
</li><li>Run the <strong>cat </strong><strong>/etc/patroni/patroni.yml</strong> command to open the <strong>patroni.yml</strong> file.</li><li>Find and record the value of <strong>namespace</strong>, as shown in the following figure.<p><span><img src="en-us_image_0000001953608009.png"></span></p>
</li><li>Run the <strong>etcdctl del --prefix " </strong><em>namespace</em><strong> "</strong> command to delete etcd data.<p>Example: <strong>etcdctl del --prefix " </strong><strong>/service148new/ "</strong></p>
</li></ol>
</li><li>To restore a PostgreSQL cluster deployed based on Patroni using log copies to its original location in 1.6.0 and later versions, you need to configure the <strong>patroni.yml</strong> file in advance. The configuration is as follows:<p>In the <strong>patroni.yml</strong> file, add the following configuration under <strong>bootstrap</strong>:</p>
<pre class="screen"> method: OceanProtectPITR
 OceanProtectPITR:
    command: "mv <em>$PGDATA/../OceanProtectData/DATADIR $PGDATA/../</em>"
    no_params: True
    keep_existing_recovery_conf: True</pre>
<div class="note"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul><li><em>$PGDATA/../</em> is the upper-level directory of the data directory, for example, <strong>/usr/local/pgsqltest</strong>.</li><li><em>DATADIR</em> in <em>$PGDATA/../OceanProtectData/DATADIR</em> indicates the data directory name, for example, <strong>/usr/local/pgsqltest/OceanProtectData/data</strong>.</li></ul>
</div></div>
</li></ul>
<div class="section"><h4 class="sectiontitle">Procedure</h4><ol><li><span>Choose <span class="uicontrol" id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001839142377_uicontrol6167212279"><b><span id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001839142377_text1816152172710"><strong>Explore</strong></span> &gt; <span id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001839142377_text1816021152712"><strong>Copy Data</strong></span> &gt; <span id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001839142377_text19649165519496"><strong>Databases</strong></span> &gt; PostgreSQL</b></span>.</span></li><li><span>You can search for copies by PostgreSQL instance resource or copy. This section describes how to search for copies by resource.</span><p><p>On the <span class="uicontrol"><b><span><strong>Resources</strong></span></b></span> tab page, locate the resource to be restored by resource name and click the name.</p>
</p></li><li><span>Select the year, month, and day in sequence to find the copy.</span><p><p>If <span><img src="en-us_image_0000001839202085.png"></span> is displayed below a month or date, copies exist in the month or on the day.</p>
</p></li><li><span>Restore data to a specified point in time or using a specific copy.</span><p><div class="p"><a href="#EN-US_TOPIC_0000001792402656__table194961441141219">Table 1</a> describes the related parameters.
<div class="tablenoborder"><a name="EN-US_TOPIC_0000001792402656__table194961441141219"></a><a name="table194961441141219"></a><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001792402656__table194961441141219" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters for restoring a PostgreSQL instance</caption><colgroup><col style="width:32.019999999999996%"><col style="width:67.97999999999999%"></colgroup><thead align="left"><tr><th align="left" class="cellrowborder" valign="top" width="32.019999999999996%" id="mcps1.3.5.2.4.2.1.2.2.3.1.1"><p>Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="67.97999999999999%" id="mcps1.3.5.2.4.2.1.2.2.3.1.2"><p>Description</p>
</th>
</tr>
</thead>
<tbody><tr><td class="cellrowborder" valign="top" width="32.019999999999996%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.1 "><p><span><strong>Restore To</strong></span></p>
</td>
<td class="cellrowborder" valign="top" width="67.97999999999999%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.2 "><p>Select either <span class="uicontrol"><b><span><strong>Original location</strong></span></b></span> or <span class="uicontrol"><b><span><strong>New location</strong></span></b></span>.</p>
<div class="note"><span class="notetitle"> NOTE: </span><div class="notebody"><p>When performing restoration to a new location, if the copy has a tablespace directory other than the data directory, ensure that the operating system user who installs the database in the new location instance can access the tablespace directory with the same name on the host in the new location.</p>
</div></div>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="32.019999999999996%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.1 "><p><span><strong>Location</strong></span></p>
</td>
<td class="cellrowborder" valign="top" width="67.97999999999999%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.2 "><p>If you select <span class="uicontrol"><b><span><strong>Original location</strong></span></b></span> for restoration, the location of the current instance is displayed by default.</p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="32.019999999999996%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.1 "><p><span><strong>Target Host</strong></span></p>
</td>
<td class="cellrowborder" valign="top" width="67.97999999999999%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.2 "><p>Specify the target host, which is mandatory if you select <span class="uicontrol"><b><span><strong>New location</strong></span></b></span> for restoration.</p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="32.019999999999996%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.1 "><p><span><strong>Target Instance</strong></span></p>
</td>
<td class="cellrowborder" valign="top" width="67.97999999999999%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.2 "><p>Specify the target instance, which is mandatory if you select <span class="uicontrol"><b><span><strong>New location</strong></span></b></span> for restoration.</p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="32.019999999999996%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.1 "><p><span><strong>Script to Run Before Restoration</strong></span></p>
</td>
<td class="cellrowborder" rowspan="3" valign="top" width="67.97999999999999%" headers="mcps1.3.5.2.4.2.1.2.2.3.1.2 "><p>You can execute a self-defined script before a restoration job is executed or after it succeeds or fails, all based on your needs. You need to enter the absolute path of the script.</p>
<ul><li>The Windows OS supports <span class="uicontrol"><b>.bat</b></span> scripts.</li><li>Non-Windows OSs support <span class="uicontrol"><b>.sh</b></span> scripts.<div class="note" id="EN-US_TOPIC_0000001792402656__note116601417195112"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001264099602_p196461512103113">If <span class="uicontrol" id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001264099602_uicontrol180112781919"><b><span id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001264099602_text10711756153116"><strong>Script to Run upon Restoration Success</strong></span></b></span> is configured, the status of the restoration job is displayed as <span class="uicontrol" id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001264099602_uicontrol488919204209"><b><span id="EN-US_TOPIC_0000001792402656__en-us_topic_0000001264099602_text186291135132417"><strong>Succeeded</strong></span></b></span> on the <span id="EN-US_TOPIC_0000001792402656__text712055613536">OceanProtect</span> even if the script fails to be executed. Check whether the job details contain a message indicating that the post-processing script fails to be executed. If yes, modify the script in a timely manner. </p>
</div></div>
</li></ul>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" headers="mcps1.3.5.2.4.2.1.2.2.3.1.1 "><p><span><strong>Script to Run upon Restoration Success</strong></span></p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" headers="mcps1.3.5.2.4.2.1.2.2.3.1.1 "><p><span><strong>Script to Run upon Restoration Failure</strong></span></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</p></li><li><span>Click <span class="uicontrol"><b>OK</b></span>.</span></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="en-us_topic_0000001792402720.html">Restoration</a></div>
</div>
</div>

<div class="hrcopyright"><hr size="2"></div><div class="hwcopyright">Copyright &copy; Huawei Technologies Co., Ltd.</div></body>
</html>